package com.speaktoitcookbook.dao.proxy;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.speaktoitcookbook.bean.ThirdAccount;
import com.speaktoitcookbook.bean.UserInfo;
import com.speaktoitcookbook.dao.IThirdAccountDao;
import com.speaktoitcookbook.dao.impl.ThirdAccountDaoImpl;
import com.speaktoitcookbook.db.Database;

/**
 * 用户三方账号数据操作代理类
 * 
 * @author 赛艳志
 * 
 */
public class ThirdAccountDaoProxy implements IThirdAccountDao {
    private Connection conn;
    private IThirdAccountDao dao;

    public ThirdAccountDaoProxy() {
        this.conn = Database.getConnection();
        this.dao = new ThirdAccountDaoImpl(conn);
    }

    @Override
    public boolean doCreate(ThirdAccount thirdAccount) throws SQLException {
        boolean result = false;
        if (null != thirdAccount) {
            try {
                result = dao.doCreate(thirdAccount);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doDelete(ThirdAccount thirdAccount) throws SQLException {
        boolean result = false;
        if (null != thirdAccount) {
            try {
                result = dao.doDelete(thirdAccount);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public boolean doUpdate(ThirdAccount thirdAccount) throws SQLException {
        boolean result = false;
        if (null != thirdAccount) {
            try {
                result = dao.doUpdate(thirdAccount);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public List<ThirdAccount> getThirdAccount(String userID)
            throws SQLException {
        List<ThirdAccount> result = null;
        if ((null != userID) && (!userID.isEmpty())) {
            try {
                result = dao.getThirdAccount(userID);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }

    @Override
    public List<UserInfo> getThirdAccount(Object... params) throws SQLException {
        List<UserInfo> result = null;
        if (null != params) {
            try {
                result = dao.getThirdAccount(params);
            } catch (SQLException e) {
                throw e;
            } finally {
                Database.close(conn);
            }
        }
        return result;
    }
}
